//package com.example.tse.rbyair.secondclassiify.adapter;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.drawable.Drawable;
//import android.os.Handler;
//import android.text.SpannableString;
//import android.text.Spanned;
//import android.text.style.StrikethroughSpan;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup;
//import android.widget.BaseAdapter;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.IntegrateConst;
//import com.rbyair.app.R;
//import com.rbyair.app.activity.LoginActivity;
//import com.rbyair.app.activity.ProductDetialActivity2;
//import com.rbyair.app.activity.ReclassifyActivity;
//import com.rbyair.app.util.CommonUtils;
//import com.rbyair.app.util.RbImageLoader;
//import com.rbyair.app.util.SharedPreferenceUtils;
//import com.rbyair.app.vo.ShopCartNumEvent;
//import com.rbyair.app.widget.AddShopCartDialog;
//import com.rbyair.app.widget.AddShopCartDialog.OnMutiplTagClickedListener;
//import com.rbyair.services.RemoteServiceFactory;
//import com.rbyair.services.goods.model.GoodsGetRequest;
//import com.rbyair.services.goods.model.GoodsGetResponse;
//import com.rbyair.services.goods.model.GoodsGetSimilarInfoProduct;
//import com.rbyair.services.goods.model.GoodsGetSpecs;
//import com.rbyair.services.shopping.model.ShoppingAddRequest;
//import com.rbyair.services.shopping.model.ShoppingAddResponse;
//import com.rudder.core.http.RemoteServiceListener;
//
//import de.greenrobot.event.EventBus;
//
//public class ReclassifyProductAdapter extends BaseAdapter {
//
//	private Context c;
//	private List<GoodsGetSimilarInfoProduct> lists = new ArrayList<GoodsGetSimilarInfoProduct>();
//	private LayoutInflater inflater;
//	private String rudder_position;
//	private String rudder_route;
//
//	ViewHolder viewHolder = null;
////	private GoodsGetSimilarInfoProduct item;
//	private HolderClickListener holderClickListener ;
//
//	public ReclassifyProductAdapter(Context c, String rudder_route,
//			String rudder_position) {
//		this.c = c;
//		inflater = LayoutInflater.from(c);
//		this.rudder_route = rudder_route;
//		this.rudder_position = rudder_position;
//	}
//
//	public void setData(List<GoodsGetSimilarInfoProduct> lists) {
//		this.lists.clear();
//		this.lists.addAll(lists);
//		notifyDataSetChanged();
//
//
//
//		for (int i = 0; i < lists.size(); i++) {
//			GoodsGetSimilarInfoProduct info = lists.get(i);
//			Log.d("lc", "ReclassifyProductAdapter productId:" + info.getProductId());
//		}
//	}
//
//	public void addMoreData(List<GoodsGetSimilarInfoProduct> lists) {
//		this.lists.addAll(lists);
//		notifyDataSetChanged();
//	}
//
//	@Override
//	public int getCount() {
//		if (lists.size()%2==1) {
//			return lists.size() + 1;
//		}
//		return lists.size();
//	}
//
//	@Override
//	public Object getItem(int position) {
//		return lists.get(position);
//	}
//
//	@Override
//	public long getItemId(int position) {
//		return position;
//	}
//
//	@Override
//	public View getView(final int position, View convertView, ViewGroup parent) {
//
//		final GoodsGetSimilarInfoProduct item;
//		if (position == (getCount() - 1) && (lists.size() % 2 == 1)) {
//			item = lists.get(position-1);
//		} else {
//			Log.d("lc", "ReclassifyProductAdapter position:" + position);
//			item = lists.get(position);
//		}
//		if (convertView == null) {
//			convertView = View.inflate(c, R.layout.stockpile_item, null);
//			viewHolder = new ViewHolder();
//
//			viewHolder.emptyTxt = (TextView) convertView
//					.findViewById(R.id.emptyTxt);
//			viewHolder.stockpile_lay = (RelativeLayout) convertView
//					.findViewById(R.id.stockpile_lay);
//			viewHolder.noStorebg = (ImageView) convertView
//					.findViewById(R.id.noStorebg);
//			viewHolder.iv_img = (ImageView) convertView
//					.findViewById(R.id.iv_img);
//			viewHolder.saleNameTxt = (TextView) convertView
//					.findViewById(R.id.saleNameTxt);
//			viewHolder.salePriceTxt = (TextView) convertView
//					.findViewById(R.id.salePriceTxt);
//			viewHolder.oldSalePriceTxt = (TextView) convertView
//					.findViewById(R.id.oldSalePriceTxt);
//			viewHolder.groupjoinCountTxt = (TextView) convertView
//					.findViewById(R.id.groupjoinCountTxt);
//			viewHolder.bottomLay = (LinearLayout) convertView
//					.findViewById(R.id.bottomLay);
//			viewHolder.emptyTxt = (TextView) convertView
//					.findViewById(R.id.emptyTxt);
//			viewHolder.addShopCatBtn = (ImageView) convertView.findViewById(R.id.addShopCatBtn);
//			int w = (CommonUtils.getScreenWidth(c)-CommonUtils.dip2px(c, 10))/2;
//			RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w, w);
//			viewHolder.iv_img.setLayoutParams(lp);
//
//			convertView.setTag(viewHolder);
//		} else {
//			viewHolder = (ViewHolder) convertView.getTag();
//		}
//
//
//		viewHolder.iv_img.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View arg0) {
//				if (position == (getCount() - 1) && (lists.size() % 2 == 1))
//					return;
//
//				Log.d("lichun","position:" + position + " productId:" + item.getProductId());
//				Intent intent = new Intent(c, ProductDetialActivity2.class);
//				intent.putExtra("rudder_route", rudder_position);
//				intent.putExtra("rudder_position", IntegrateConst.NEW_SORT_POSITION_ + (position + 1));
//				intent.putExtra("productId", lists.get(position).getProductId());
//				Log.d("lc", "ReclassifyProductAdapter productId" + lists.get(position).getProductId());
//
//				c.startActivity(intent);
//			}
//		});
//
//		viewHolder.addShopCatBtn.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				//						showLoadingDialog();
//				GoodsGetRequest r = new GoodsGetRequest();
//				r.setProductId(lists.get(position).getProductId());
//				r.setIsFastBuy("0");
//				r.setType("0");
//				r.setDeviceId(CommonUtils.getDeviceId(c));
//
//				RemoteServiceFactory.getInstance().getGoodsService(c).get(r, new RemoteServiceListener<GoodsGetResponse>() {
//
//					@Override
//					public void ok(GoodsGetResponse t) {
//
//						if(SharedPreferenceUtils.getValueByKey(c, "memberId").equals("") || SharedPreferenceUtils.getValueByKey(c, "memberId").isEmpty()){
//							Toast.makeText(c, "请先登录", 0).show();
//							Intent intent = new Intent(c, LoginActivity.class);
//							intent.putExtra("type", "1");
//							c.startActivity(intent);
//							return;
//						}else if (lists.get(position).getQuantity().equals("0")) {
//							Toast.makeText(c, "好东西被抢光了，正在备货中", 0).show();
//						}
//
//						boolean selecteable = false;
//						a:
//							for(GoodsGetSpecs ggs:t.getSpecs()){
//								if(ggs.getSpecValues().size()>1){
//									selecteable = true;
//									break a;
//								}
//							}
//						if(selecteable){  //有规格
//							ReclassifyActivity baseActivity = (ReclassifyActivity)c;
//							AddShopCartDialog addShopCartDialog = new AddShopCartDialog(t,position);
//							addShopCartDialog.show(baseActivity.getSupportFragmentManager(), "");
//							addShopCartDialog.setOnMutiplTagClickedListener(new OnMutiplTagClickedListener() {
//								@Override
//								public void OnClicked() {
//									if(holderClickListener!=null)
//										holderClickListener.onHolderClick(lists.get(position).getThumbnailPic(), null);
//								}
//							});
//
//						}else{   //没有规格
//							addToShopCart(t.getProductId(),t.getGoodsId(),1,lists.get(position).getThumbnailPic(),position);
//						}
//					}
//
//					private void addToShopCart(String productId,String goodsId,int count,final String img,int position) {
//						ShoppingAddRequest r = new ShoppingAddRequest();
//						r.setProductId(productId);
//						r.setGoodsId(goodsId);
//						r.setIsFastBuy("0");
//						r.setQuantity(""+count);
//						//		r.setRudder_position(rudder_position);
//						r.setLimit("");
//						r.setType("0");
//						//		r.setSecondId(secondId);
//						r.setTargetId("");
//						r.setRudder_route(rudder_position + "|"+ IntegrateConst.NEW_SORT_POSITION_ + (position + 1));
//
//						RemoteServiceFactory.getInstance().getShoppingService(c).add(r, new RemoteServiceListener<ShoppingAddResponse>() {
//
//							@Override
//							public void ok(ShoppingAddResponse t) {
//								new Handler().postDelayed(new Runnable() {
//
//									@Override
//									public void run() {
//										EventBus.getDefault().post(new ShopCartNumEvent("base"));
//										Toast toast = Toast.makeText(c, "添加购物车成功", Toast.LENGTH_SHORT);
//										toast.setGravity(Gravity.CENTER, 0, 0);
//										toast.show();
//									}
//								}, 1000);
//
//								if(holderClickListener!=null)
//								holderClickListener.onHolderClick(img, null);
//
//							}
//
//							@Override
//							public void failue(int errorCode, String errorMessage) {
//							}
//						});
//					}
//
//					@Override
//					public void failue(int errorCode,String errorMessage) {
//
//					}
//
//				});
//			}
//		});
//
//		if (position == (getCount() - 1) && (lists.size() % 2 == 1)) {
//			viewHolder.bottomLay.setVisibility(View.INVISIBLE);
//			viewHolder.iv_img.setVisibility(View.INVISIBLE);
//		} else {
//			viewHolder.bottomLay.setVisibility(View.VISIBLE);
//			viewHolder.iv_img.setVisibility(View.VISIBLE);
//			RbImageLoader
//			.displayImage(lists.get(position).getThumbnailPic(),
//					viewHolder.iv_img,
//					RbImageLoader.getSmallLogOptions());
//			viewHolder.saleNameTxt.setText(lists.get(position).getName());
//			String price = lists.get(position).getPrice();
//			viewHolder.salePriceTxt.setText("￥"
//					+ CommonUtils.formatPrice3(price));
//
//			String oldPriceString = CommonUtils.formatPrice3(lists
//					.get(position).getMktprice());
//			SpannableString sp = new SpannableString("￥" + oldPriceString);
//			sp.setSpan(new StrikethroughSpan(), 0, oldPriceString.length(),
//					Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//			viewHolder.oldSalePriceTxt.setText(sp);
//
//			viewHolder.groupjoinCountTxt.setText(lists.get(position)
//					.getBuyerNum());
//			if (lists.get(position).getQuantity().equals("0")) { // 库存0
//				viewHolder.noStorebg.setVisibility(0);
//			} else {
//				viewHolder.noStorebg.setVisibility(8);
//			}
//			RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//			lp.setMargins(150, 130, 120, 120);
//			viewHolder.noStorebg.setLayoutParams(lp);
//		}
//
//		return convertView;
//	}
//
//	class ViewHolder {
//		LinearLayout bottomLay;
//		RelativeLayout stockpile_lay;
//		ImageView iv_img;
//		ImageView addShopCatBtn;
//		TextView saleNameTxt;
//		ImageView noStorebg;
//		TextView salePriceTxt;
//		TextView oldSalePriceTxt;
//		TextView groupjoinCountTxt;
//		TextView emptyTxt;
//	}
//
//	public void SetOnSetHolderClickListener(HolderClickListener holderClickListener){
//        this.holderClickListener = holderClickListener;
//    }
//    public interface HolderClickListener{
//        public void onHolderClick(String img, int[] start_location);
//    }
//}
